package com.zxs.infra.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zxs.infra.basic.entity.SubjectJudge;
import com.zxs.infra.basic.entity.SubjectMultiple;
import com.zxs.infra.basic.mapper.SubjectJudgeMapper;
import com.zxs.infra.basic.service.SubjectJudgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 判断题选项表(SubjectJudge)表服务实现类
 *
 * @author makejava
 * @since 2025-11-12 21:05:17
 */
@Service
public class SubjectJudgeServiceImpl implements SubjectJudgeService {
    @Autowired
    private SubjectJudgeMapper subjectJudgeMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectJudge queryById(Integer id) {
        return this.subjectJudgeMapper.queryById(id);
    }


    /**
     * 新增数据
     *
     * @param subjectJudge 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectJudge insert(SubjectJudge subjectJudge) {
        this.subjectJudgeMapper.insert(subjectJudge);
        return subjectJudge;
    }

    /**
     * 修改数据
     *
     * @param subjectJudge 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectJudge update(SubjectJudge subjectJudge) {
        this.subjectJudgeMapper.update(subjectJudge);
        return this.queryById(subjectJudge.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.subjectJudgeMapper.deleteById(id) > 0;
    }

    @Override
    public Integer batchInsert(List<SubjectJudge> subjectJudges) {
        return subjectJudgeMapper.insertBatch(subjectJudges);
    }

    @Override
    public SubjectJudge queryBySubjectId(int subjectId) {
        LambdaQueryWrapper<SubjectJudge> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SubjectJudge::getSubjectId, subjectId);
        SubjectJudge subjectJudge = subjectJudgeMapper.selectOne(queryWrapper);
        return subjectJudge;
    }
}
